package com.code.port;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * @description: 查看前1024端口那个端口安装有TCP服务器
 * @className: PortScanner
 * @package: com.code.port
 * @author: yangzhi@hsyuntai.com
 * @date: 2019/10/17 15:20
 * @copyright: 版权归 HSYUNTAI 所有
 */
public class PortScanner {

    public static void main(String[] args) {
        String host = "127.0.0.1";

        for (int i = 1; i < 1024; i++) {
            try {
                Socket s = new Socket(host, i);
                System.out.println("This port:" + i + " open of " + host);
                s.close();
            } catch (UnknownHostException e) {
                System.out.println(e);
                break;
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }
    }

}



